import Vue from 'vue';
import Router from 'vue-router';
import {
  sessionStorage
} from "@/util";

Vue.use(Router);

let router = new Router({
  routes: [
    // 登录
    {
      name: 'login',
      path: '/login',
      alias: '/',
      component: () => import('@/pages/login')
    },
    // CPA数据管理
    {
      name: 'cpa',
      path: '/cpa',
      redirect: {
        name: 'cpa-data-report'
      },
      component: () => import('@/pages/layout'),
      children: [
        // 产品数据管理
        {
          name: 'cpa-data-report',
          path: 'data-report',
          meta: {
            index: '1-1-1'
          },
          component: () => import('@/pages/cpa/data-report')
        },
        {
          name: 'cpa-data-refresh',
          path: 'data-refresh',
          meta: {
            index: '1-1-2'
          },
          component: () => import('@/pages/cpa/data-refresh')
        },
        {
          name: 'cpa-data-grab',
          path: 'data-grab',
          meta: {
            index: '1-1-3'
          },
          component: () => import('@/pages/cpa/data-grab')
        },
        {
          name: 'cpa-data-business',
          path: 'data-business',
          meta: {
            index: '1-1-4'
          },
          component: () => import('@/pages/cpa/data-business')
        },

        // 客户&渠道管理
        {
          name: 'cpa-customer-info',
          path: 'customer-info',
          meta: {
            index: '1-2-1'
          },
          component: () => import('@/pages/cpa/customer-info')
        },
        {
          name: 'cpa-customer-info-detail',
          path: 'customer-info-detail',
          meta: {
            index: '1-2-1'
          },
          component: () => import('@/pages/cpa/customer-info-detail')
        },
        {
          name: 'cpa-customer-pro',
          path: 'customer-pro',
          meta: {
            index: '1-2-2'
          },
          component: () => import('@/pages/cpa/customer-pro')
        },
        {
          name: 'cpa-customer-pro-detail',
          path: 'customer-pro-detail',
          meta: {
            index: '1-2-2'
          },
          component: () => import('@/pages/cpa/customer-pro-detail')
        },
        {
          name: 'cpa-channel-info',
          path: 'channel-info',
          meta: {
            index: '1-2-3'
          },
          component: () => import('@/pages/cpa/channel-info')
        },
        {
          name: 'cpa-channel-info-detail',
          path: 'channel-info-detail',
          meta: {
            index: '1-2-3',
          },
          component: () => import('@/pages/cpa/channel-info-detail')
        },
        {
          name: 'cpa-channel-pro',
          path: 'channel-pro',
          meta: {
            index: '1-2-4'
          },
          component: () => import('@/pages/cpa/channel-pro')
        },
        {
          name: 'cpa-channel-pro-detail',
          path: 'channel-pro-detail',
          meta: {
            index: '1-2-4'
          },
          component: () => import('@/pages/cpa/channel-pro-detail')
        },
        {
          name: 'cpa-product-name',
          path: 'product-name',
          meta: {
            index: '1-2-5'
          },
          component: () => import('@/pages/cpa/product-name')
        },

        // 对账管理
        {
          name: 'cpa-account-customers',
          path: 'account-customers',
          meta: {
            index: '1-3-1'
          },
          component: () => import('@/pages/cpa/account-customers')
        },
        {
          name: 'cpa-account-channels',
          path: 'account-channels',
          meta: {
            index: '1-3-2'
          },
          component: () => import('@/pages/cpa/account-channels')
        },
        {
          name: 'cpa-account-customer',
          path: 'account-customer',
          meta: {
            index: '1-3-3'
          },
          component: () => import('@/pages/cpa/account-customer')
        },
        {
          name: 'cpa-account-channel',
          path: 'account-channel',
          meta: {
            index: '1-3-4'
          },
          component: () => import('@/pages/cpa/account-channel')
        },

        // 结算管理
        {
          name: 'cpa-final-customer-month',
          path: 'final-customer-month',
          meta: {
            index: '1-4-1'
          },
          component: () => import('@/pages/cpa/final-customer-month')
        },
        {
          name: 'cpa-final-customer-receivable',
          path: 'final-customer-receivable',
          meta: {
            index: '1-4-2'
          },
          component: () => import('@/pages/cpa/final-customer-receivable')
        },
        {
          name: 'cpa-final-channel-month',
          path: 'final-channel-month',
          meta: {
            index: '1-4-3'
          },
          component: () => import('@/pages/cpa/final-channel-month')
        },
        {
          name: 'cpa-final-channel-pay',
          path: 'final-channel-pay',
          meta: {
            index: '1-4-4'
          },
          component: () => import('@/pages/cpa/final-channel-pay')
        },
        {
          name: 'cpa-final-receivable',
          path: 'final-receivable',
          meta: {
            index: '1-4-5'
          },
          component: () => import('@/pages/cpa/final-receivable')
        },
        {
          name: 'cpa-final-pay',
          path: 'final-pay',
          meta: {
            index: '1-4-6'
          },
          component: () => import('@/pages/cpa/final-pay')
        }
      ]
    },
    // 信息流管理
    {
      name: 'flow',
      path: '/flow',
      redirect: {
        name: 'flow-customer'
      },
      component: () => import('@/pages/layout'),
      children: [
        {
          name: 'flow-customer',
          path: 'customer',
          meta: {
            index: '2-1'
          },
          component: () => import('@/pages/flow/customer')
        }, {
          name: 'flow-customer-detail',
          path: 'customer-detail',
          meta: {
            index: '2-1'
          },
          component: () => import('@/pages/flow/customer-detail')
        }, {
          name: 'flow-customer-aptitude',
          path: 'customer-aptitude',
          meta: {
            index: '2-2'
          },
          component: () => import('@/pages/flow/customer-aptitude')
        }, {
          name: 'flow-customer-aptitude-detail',
          path: 'customer-aptitude-detail',
          meta: {
            index: '2-2'
          },
          component: () => import('@/pages/flow/customer-aptitude-detail')
        }, {
          name: 'flow-platform',
          path: 'platform',
          meta: {
            index: '2-3'
          },
          component: () => import('@/pages/flow/platform')
        }, {
          name: 'flow-platform-detail',
          path: 'platform-detail',
          meta: {
            index: '2-3'
          },
          component: () => import('@/pages/flow/platform-detail')
        }, {
          name: 'flow-product-name',
          path: 'product-name',
          meta: {
            index: '2-4'
          },
          component: () => import('@/pages/flow/product-name')
        }, {
          name: 'flow-product',
          path: 'product',
          meta: {
            index: '2-5'
          },
          component: () => import('@/pages/flow/product')
        }, {
          name: 'flow-product-detail',
          path: 'product-detail',
          meta: {
            index: '2-5'
          },
          component: () => import('@/pages/flow/product-detail')
        }, {
          name: 'flow-product-rebate-detail',
          path: 'product-rebate-detail',
          meta: {
            index: '2-5'
          },
          component: () => import('@/pages/flow/product-rebate-detail')
        }, {
          name: 'flow-product-status-detail',
          path: 'product-status-detail',
          meta: {
            index: '2-5'
          },
          component: () => import('@/pages/flow/product-status-detail')
        }, {
          name: 'flow-product-principal-detail',
          path: 'product-principal-detail',
          meta: {
            index: '2-5'
          },
          component: () => import('@/pages/flow/product-principal-detail')
        },{
          name: 'flow-product-serve-detail',
          path: 'product-serve-detail',
          meta: {
            index: '2-5'
          },
          component: () => import('@/pages/flow/product-serve-detail')
        },  {
          name: 'flow-account',
          path: 'account',
          meta: {
            index: '2-6'
          },
          component: () => import('@/pages/flow/account')
        }, {
          name: 'flow-account-detail',
          path: 'account-detail',
          meta: {
            index: '2-6'
          },
          component: () => import('@/pages/flow/account-detail')
        }, {
          name: 'flow-accountdata',
          path: 'accountdata',
          meta: {
            index: '2-7'
          },
          component: () => import('@/pages/flow/accountdata')
        }, {
          name: 'flow-customer-reconciliation',
          path: 'customer-reconciliation',
          meta: {
            index: '2-8'
          },
          component: () => import('@/pages/flow/customer-reconciliation')
        }, {
          name: 'flow-statements',
          path: 'statements',
          meta: {
            index: '2-9'
          },
          component: () => import('@/pages/flow/statements')
        },{
          name: 'flow-statements-detail',
          path: 'statements-detail',
          meta: {
            index: '2-9'
          },
          component: () => import('@/pages/flow/statements-detail')
        },{
          name: 'flow-invoice',
          path: 'invoice',
          meta: {
            index: '2-10'
          },
          component: () => import('@/pages/flow/invoice')
        },{
          name: 'flow-invoice-detail',
          path: 'invoice-detail',
          meta: {
            index: '2-10'
          },
          component: () => import('@/pages/flow/invoice-detail')
        },{
          name: 'flow-invoice-statements',
          path: 'invoice-statements',
          meta: {
            index: '2-10'
          },
          component: () => import('@/pages/flow/invoice-statements')
        }
        
      ]
    },

    // 合同管理
    {
      name: 'contract',
      path: '/contract',
      redirect: {
        name: 'contract-contract-customer'
      },
      component: () => import('@/pages/layout'),
      children: [ // 合同管理
        {
          name: 'contract-contract-customer',
          path: 'contract-customer',
          meta: {
            index: '3-1'
          },
          component: () => import('@/pages/contract/contract-customer')
        },
        {
          name: 'contract-contract-customer-detail',
          path: 'contract-customer-detail',
          meta: {
            index: '3-1'
          },
          component: () => import('@/pages/contract/contract-customer-detail')
        },
        {
          name: 'contract-contract-channel',
          path: 'contract-channel',
          meta: {
            index: '3-2'
          },
          component: () => import('@/pages/contract/contract-channel')
        },
        {
          name: 'contract-contract-channel-detail',
          path: 'contract-channel-detail',
          meta: {
            index: '3-2'
          },
          component: () => import('@/pages/contract/contract-channel-detail')
        }
      ]
    },
    // 广告
    {
      name: 'advertise',
      path: '/advertise',
      redirect: {
        name: 'advertise'
      },
      component: () => import('@/pages/layout'),
      children: [
        {
          name: 'advertise',
          path: 'advertise',
          meta: {
            index: '4-1'
          },
          component: () => import('@/pages/advertise/advertise')
        }, 
        {
          name: 'advertise-detail',
          path: 'advertise-detail',
          meta: {
            index: '4-1',
          },
          component: () => import('@/pages/advertise/advertise-detail')
        }, 
        {
          name: 'advertise-detail-new',
          path: 'advertise-detail-new',
          meta: {
            index: '4-1',
          },
          component: () => import('@/pages/advertise/advertise-detail-new')
        }, 
        {
          name: 'advertise-administration',
          path: 'advertise-administration',
          meta: {
            index: '4-2',
          },
          component: () => import('@/pages/advertise/advertise-administration')
        },
        {
          name: 'advertise-accountManagement',
          path: 'advertise-accountManagement',
          meta: {
            index: '4-3',
          },
          component: () => import('@/pages/advertise/advertise-accountManagement')
          
        },
        {
          name: 'advertise-earlyWarningMode',
          path: 'advertise-earlyWarningMode',
          meta: {
            index: '4-3',
          },
          component: () => import('@/pages/advertise/advertise-earlyWarningMode')
        },
        {
          name: 'advertise-group',
          path: 'advertise-group',
          meta: {
            index: '4-4',
          },
          component: () => import('@/pages/advertise/advertise-group')
        },
        {
          name: 'advertise-autoBuild',
          path: 'advertise-autoBuild',
          meta: {
            index: '4-5',
          },
          component: () => import('@/pages/advertise/advertise-autoBuild')
        },
        {
          name: 'advertise-autoBuild-detail',
          path: 'advertise-autoBuild-detail',
          meta: {
            index: '4-5',
          },
          component: () => import('@/pages/advertise/advertise-autoBuild-detail')
        },  
      ]
    },
    {
      name: 'toutiao',
      path: '/toutiao',
      redirect: {
        name: 'toutiao'
      },
      component: () => import('@/pages/layout'),
      children: [
        {
          name: 'toutiao',
          path: 'toutiao',
          meta: {
            index: '5-1'
          },
          component: () => import('@/pages/toutiao/toutiao')
        }, 
        {
          name: 'toutiao-detail',
          path: 'toutiao-detail',
          meta: {
            index: '5-2'
          },
          component: () => import('@/pages/toutiao/toutiao-detail')
        }, 
        {
          name: 'toutiao-see',
          path: 'toutiao-see',
          meta: {
            index: '5-3'
          },
          component: () => import('@/pages/toutiao/toutiao-see')
        }, 
        
      ]
    },
    {
      name: 'toutiao-currency',
      path: '/toutiao-currency',
      redirect: {
        name: 'toutiao-currency-toutiao'
      },
      component: () => import('@/pages/layout'),
      children: [
        {
          name: 'toutiao-currency-toutiao',
          path: 'toutiao-currency-toutiao',
          meta: {
            index: '6-1'
          },
          component: () => import('@/pages/toutiao-currency/toutiao')
        }, 
        {
          name: 'toutiao-currency-detail',
          path: 'toutiao-currency-detail',
          meta: {
            index: '6-1',
          },
          component: () => import('@/pages/toutiao-currency/toutiao-currency-detail')
        }, 
        {
          name: 'choose-material',
          path: 'choose-material',
          meta: {
            index: '6-2'
          },
          component: () => import('@/pages/toutiao-currency/choose-material')
        }, 
        {
          name:'choose-landingpage',
          path:'choose-landingpage',
          meta:{
            index:'6-2'
          },
          component: ()=> import('@/pages/toutiao-currency/choose-landingpage')
        },
        {
          name: 'toutiao-accountManagement',
          path: 'toutiao-accountManagement',
          meta: {
            index: '6-2'
          },
          component: () => import('@/pages/toutiao-currency/toutiao-accountManagement')
        },
        {
          name: 'toutiao-earlyWarningMode',
          path: 'toutiao-earlyWarningMode',
          meta: {
            index: '6-2'
          },
          component: () => import('@/pages/toutiao-currency/toutiao-earlyWarningMode')

        }
        // {
        //   name: 'toutiao-see',
        //   path: 'toutiao-see',
        //   meta: {
        //     index: '7-3'
        //   },
        //   component: () => import('@/pages/toutiao-currency/toutiao-see')
        // }, 
      ]
    },
 // 丁丁后台
    {
      name: 'ding',
      path: '/ding',
      redirect: {
        name: 'ding'
      },
      component: () => import('@/pages/layout'),
      children: [
        {
          name: 'ding',
          path: 'ding',
          meta: {
            index: '7-1'
          },
          component: () => import('@/pages/ding/ding')
        }, 
        {
          name: 'ding-detail',
          path: 'ding-detail',
          meta: {
            index: '7-1'
          },
          component: () => import('@/pages/ding/ding-detail')
        }, 
        {
          name: 'ding-set',
          path: 'ding-set',
          meta: {
            index: '7-2'
          },
          component: () => import('@/pages/ding/ding-set')
        }, 
        {
          name: 'ding-grant',
          path: 'ding-grant',
          meta: {
            index: '7-1'
          },
          component: () => import('@/pages/ding/ding-grant')
        }, 
        {
          name: 'ding-push',
          path: 'ding-push',
          meta: {
            index: '7-1'
          },
          component: () => import('@/pages/ding/ding-push')
        }, 
      ]
    },
    {
      name: 'daily',
      path: '/daily',
      redirect: {
        name: 'daily'
      },
      component: () => import('@/pages/layout'),
      children: [
        {
          name: 'ding',
          path: 'ding',
          meta: {
            index: '7-2'
          },
          component: () => import('@/pages/daily/ding')
        }, 
        {
          name: 'daily-detail',
          path: 'daily-detail',
          meta: {
            index: '7-2'
          },
          component: () => import('@/pages/daily/ding-detail')
        }, 
        {
          name: 'daily-set',
          path: 'daily-set',
          meta: {
            index: '7-2'
          },
          component: () => import('@/pages/daily/ding-set')
        }, 
        {
          name: 'daily-grant',
          path: 'daily-grant',
          meta: {
            index: '7-2'
          },
          component: () => import('@/pages/daily/ding-grant')
        }, 
        {
          name: 'daily-push',
          path: 'daily-push',
          meta: {
            index: '7-2'
          },
          component: () => import('@/pages/daily/ding-push')
        }, 
      ]
    },
    //删除评论
    {
      name:"comments",
      path:"/comments",
      component: () => import('@/pages/layout'),
      children: [
        {
          name: 'delete-comments',
          path: 'delete-comments',
          meta: {
            index: '8-1'
          },
          component: () => import('@/pages/comments/delete-comments')
        }, 
        {
          name: 'delete-comments-new',
          path: 'delete-comments-new',
          meta: {
            index: '8-2'
          },
          component: () => import('@/pages/comments/delete-comments-new')
        }, 
        {
          name: 'delete-commentsTT',
          path: 'delete-commentsTT',
          meta: {
            index: '8-3'
          },
          component: () => import('@/pages/comments/delete-commentsTT')
        }, 
      ]
    },
    {
      path: '*',
      component: () => import('@/pages/not-found')
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return {
        x: 0,
        y: 0
      };
    }
  }
});

router.beforeEach((to, from, next) => {
  if (sessionStorage.get("user") || to.name === "login") {
    next();
  } else {
    next({
      name: "login"
    });
  }
});

export default router;